import {mapBase} from "../base/common/Constants";
import Toast from "../base/utils/Toast";
import {dateToDateString} from "../base/utils/Utils";
import MapLogic from "./MapLogic";

const {ccclass, property} = cc._decorator;

@ccclass
export default class MapItem extends cc.Component {

    @property(cc.Label) decLabel:cc.Label = null;

    move:number = 1;

    mapData:mapBase = null;

    curTime;

    map:MapLogic = null;

    protected onLoad() {
        this.node.on(cc.Node.EventType.TOUCH_START, this.onTouchStart, this);
        this.node.on(cc.Node.EventType.TOUCH_END, this.onTouchEnd, this);
    }

    onTouchStart(){
        this.curTime = new Date().getTime();
    }

    onTouchEnd(){
        if( (new Date().getTime() - this.curTime) > 500){
            console.log(this.mapData)
            if(this.mapData.pushBuild != -1 || this.mapData.getBuild != -1){
                this.map.showPro((this.mapData.pushBuild != -1 ? 0 : 1),this);
            }
        }
    }

    init(m:mapBase,map){
        this.move = m.open;
        this.mapData = m;
        this.map = map;
        this.decLabel.string = '';

    }

    changeMap(type){
        switch (type){
            case 0:
                this.mapData.open = 0;
                this.node.children[0].opacity = 200;
                this.node.children[2].active = false;
                this.node.children[3].active = false;
                this.node.children[5].active = false;

                this.mapData.pushBuild = -1;
                this.mapData.getBuild = -1;
                this.decLabel.string = '';

                break;

            case 1:
                this.mapData.open = 1;
                this.node.children[0].opacity = 100;
                this.node.children[2].active = true;
                this.node.children[3].active = false;
                this.node.children[5].active = false;
                this.mapData.pushBuild = -1;
                this.mapData.getBuild = 0;
                this.decLabel.string = '';


                break;
            case 2:
                this.mapData.open = 1;
                this.node.children[0].opacity = 100;
                this.node.children[2].active = false;
                this.node.children[3].active = true;
                this.node.children[5].active = false;
                this.mapData.pushBuild = 0;
                this.mapData.getBuild = -1;
                this.decLabel.string = '';


                break;

            case 3:
                this.mapData.open = 1;
                this.node.children[0].opacity = 100;
                this.node.children[2].active = false;
                this.node.children[3].active = false;
                this.node.children[5].active = false;
                this.decLabel.string = '';


                break;
            case 4:
               if(this.mapData.open == 0){
                   Toast('墙体上不可放置出生点');
                   return;
               }
                this.node.children[4].active = !this.node.children[4].active;
                this.decLabel.string = '';
                this.mapData.spawn_point = 1;

                break;

        }

    }

}
